class StoreController < ApplicationController
  
  # skip_before_filter :authorize

  def index
    
    flash[:store_page] = "yes"
    # @products = Product.all
    # @products = Product.paginate :page => params[:page], :per_page => 10
   #  @cart = current_cart
   #  @count = increment_count
   #  @shown_message = "(You've been here #{@count} times)" if session[:counter] >5
    unless params[:keyword]
      @products = Product.paginate :page => params[:page], :per_page => 10
      @image = @products.first.image_url
       @cart = current_cart
       @count = increment_count
       @shown_message = "(You've been here #{@count} times)" if session[:counter] >5
       
      
    else
      # @products = Product.find_by_sql("select * from products where title like ?", params[:keyword])
      @products = Product.where("title like ?", "%"+params[:keyword]+"%").paginate :page => params[:page], :per_page => 10
    end
  end

  def increment_count
    if session[:counter].nil?
      session[:counter] = 0
    end
    session[:counter] += 1
  end


end
